package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonTeacherListSutendSpeakDataBean;
import com.fancy.learncenter.ui.activity.CartoonTeacherClassDetailActivity;
import com.fancy.learncenter.ui.activity.CartoonTeacherEveryDayDetailActivity;
import com.fancy.learncenter.ui.activity.CartoonTeacherEveryDayPreviewActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by Fancy on 2018/1/29.
 * Explain activity as
 */

public class CartoonTeacherEveryDayReportAdapter extends CommonRecycleViewAdapter<CartoonTeacherListSutendSpeakDataBean.ResultBean> {
    String classId;

    public CartoonTeacherEveryDayReportAdapter(Context mContext, List<CartoonTeacherListSutendSpeakDataBean.ResultBean> itemDatas, String classId) {
        super(mContext, R.layout.teacher_everyday_report_detail_item, itemDatas);

        this.classId = classId;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonTeacherListSutendSpeakDataBean.ResultBean item, final int position) {
        SimpleDraweeView head_icon = customViewHold.getView(R.id.head_icon);
        head_icon.setImageURI(item.getHeadImgurl());

        TextView head_name = customViewHold.getView(R.id.head_name);
        head_name.setText(item.getStudentName());

        TextView urge_text = customViewHold.getView(R.id.urge_text);
        TextView right_arrow = customViewHold.getView(R.id.right_arrow);


        TextView commit_times = customViewHold.getView(R.id.commit_times);


        if (item.getCommitCount() > 0) {
            commit_times.setText(item.getCommitCount() + "道");

            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Intent intent = new Intent(mContext, CartoonTeacherEveryDayPreviewActivity.class);
                    intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_ID_KEY, classId);
                    intent.putExtra(CartoonTeacherEveryDayDetailActivity.STUDENT_ID_KEY, item.getStudentId());
                    intent.putExtra("studenName", item.getStudentName());
                    mContext.startActivity(intent);
                }
            });

            urge_text.setVisibility(View.GONE);
            right_arrow.setVisibility(View.VISIBLE);

        } else {
            commit_times.setText("未完成");
            right_arrow.setVisibility(View.GONE);
            if ("0".equals(item.getNodifyState())) {
                urge_text.setText("催促");
                urge_text.setTextColor(Color.parseColor("#00C9B9"));

                urge_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (urgeCallBackl != null) {
                            urgeCallBackl.urgeCallBackClick(item.getStudentId(), position);
                        }
                    }
                });
            } else {
                urge_text.setText("已催");
                urge_text.setTextColor(Color.parseColor("#9D9D9D"));
            }
        }


    }

    private TeacherReportDetailAdapter.UrgeCallBack urgeCallBackl;

    public TeacherReportDetailAdapter.UrgeCallBack getUrgeCallBackl() {
        return urgeCallBackl;
    }

    public void setUrgeCallBackl(TeacherReportDetailAdapter.UrgeCallBack urgeCallBackl) {
        this.urgeCallBackl = urgeCallBackl;
    }

    public interface UrgeCallBack {
        abstract void urgeCallBackClick(String studentHomeworkId, int position);
    }

}
